package com.sikaryofficial.backend.service.article.event;

import com.sikaryofficial.backend.constant.ArticleAuditStatusEnum;
import com.sikaryofficial.backend.service.article.cache.ArticleCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author : qinjinyuan
 * @desc : 评价监听
 * @date : 2023/11/01 17:29
 */
@Component
@Slf4j
public class ArticleListener {
    @Autowired
    private ArticleCacheService articleCacheService;
    /**
     * 监听 文章计算事件
     *
     * @param event
     */
    @EventListener
    public void processCountEvent(ArticleCountEvent event) {
        articleCacheService.loadArticleStatistics();
    }

    @EventListener
    public void processCountWithAudit(AuditEvent event) {
        boolean reviewFlag = ArticleAuditStatusEnum.APPROVED.getCode().equals(event.getAuditStatus());
        if (!reviewFlag) {
            log.info("==========================>>getAuditStatus:{}", event.getAuditStatus());
            return;
        }
        articleCacheService.loadArticleStatistics();
    }
}
